<?php
namespace app\admin\controller;

use app\admin\module\GoodscateModule;
use app\BaseController;
use app\Request;
use app\common\validate\Goodscate as GoodscateValidate;
use think\Exception;

class Goodscate extends BaseController{

    public function index(Request $request){
        $pageSize = $request->param('pageSize',10);
        $data = GoodscateModule::page($pageSize);
        return $this->success('ok',$data);
    }

    public function create(Request $request){
        $data = $request->post();
        $validate = new GoodscateValidate();
        if(!$validate->check($data)){
            throw new Exception($validate->getError());
        }
        GoodscateModule::create($data);
        return $this->success("新增成功");
    }

    public function update(Request $request){
        $data = $request->post();
        $validate = new GoodscateValidate();
        if(!$validate->check($data)){
            throw new Exception($validate->getError());
        }
        GoodscateModule::update($data);
        return $this->success("更新成功");
    }

    public function remove(Request $request){
        $id = $request->param('id');
        GoodscateModule::del($id);
        return $this->success('ok');
    }

}
